* bar graphs of causes of cognitive deficits (stunting, sanitation, anemia, lead)

cd "~/Documents/econ/research/current/cognitive/estimation/data"

set scheme s2color, permanently
graph set window fontface "CMU Serif"

use WDI, clear
merge 1:1 countrycode year using lead, nogen
merge 1:1 countrycode year using stunt2000, nogen
tab year

local sani "water sanitation defecate"
local disease "malaria hiv"
local other "undernut anemia lead"

gen no_san = 100-sanitation

discard
adopath ++"~/Documents/econ/research/stata/ado/personal/barci"
local com `"yscale(range(0 75)) ylabel(none) ytitle("") xsize(2) ysize(2)"'
local xlab `"xlabel(1 "Low Income" 2 "Lower Mid" 3 "Upper Mid" 4 "High Income", angle(25))"'
barci stunt if year==2000, over(wb_cat) name(stunt) ///
	title("Undernutrition") color(dkorange) `com' `xlab' ///
	ytitle("% of children", size(*1.2)) text(75 2.5 "(Child Stunting)")	
graph export ../../draft/images/stunt.pdf, fontface("CMU Serif") replace
barci no_san if year==2017, over(wb_cat) name(sanitation)  ///
	title("Lacking Sanitation") color(forest_green) `com' `xlab' 
graph export ../../draft/images/sanitation.pdf, fontface("CMU Serif") replace
barci anemia if year==2019, over(wb_cat) name(anemia) ///
	title("Child Anemia") color(maroon) `com' `xlab' 
graph export ../../draft/images/anemia.pdf, fontface("CMU Serif") replace
barci lead_BLL5 if year==2019, over(wb_cat) name(lead) ///
	title("Child Lead Exposure") color(gray) `com' `xlab' 
graph export ../../draft/images/lead_BLL5.pdf, fontface("CMU Serif") replace
graph combine stunt sanitation anemia lead, rows(1) ysize(2) iscale(*1.7)
graph export ../../draft/images/riskfact.pdf, fontface("CMU Serif") replace

// --- now for slides ---

local pct `"ytitle("Percent", size(*1.2)) xlabel(1 "Low Income" 2 "Lower Mid" 3 "Upper Mid" 4 "High Income", angle(25))"'
barci stunt if year==2000, over(wb_cat) name(stunt_s) ///
	title("Malnutrition") color(dkorange) `com' `pct' ///
	text(75 2.5 "(Child Stunting)")
graph export ../../draft/images/stunt_s.pdf, fontface("CMU Serif") replace
barci no_san if year==2017, over(wb_cat) name(sanitation_s)  ///
	title("Lacking Sanitation") color(forest_green) `com' `pct'
graph export ../../draft/images/sanitation_s.pdf, fontface("CMU Serif") replace
barci anemia if year==2019, over(wb_cat) name(anemia_s) ///
	title("Child Anemia") color(maroon) `com' `pct'
graph export ../../draft/images/anemia_s.pdf, fontface("CMU Serif") replace
barci lead_BLL5 if year==2019, over(wb_cat) name(lead_s) ///
	title("Child Lead Exposure") color(gray) `com' `pct'
graph export ../../draft/images/lead_BLL5_s.pdf, fontface("CMU Serif") replace
graph combine stunt_s sanitation_s anemia_s lead_s, rows(1) ysize(2) ///
	iscale(*1.7) title("High Levels of Risk Worldwide", size(*1.5))
graph export ../../draft/images/riskfact_slide.pdf, fontface("CMU Serif") replace

// values for Korea
l undernut if year==2018 & countrycode=="KOR"
l no_san if year==2017 & countrycode=="KOR"
l anemia if year==2019 & countrycode=="KOR"
l lead_BLL5 if year==2019 & countrycode=="KOR"
exit

encode(countrycode), gen(isonum)
xtset isonum year
// n.b. data available: undernut 2001-2019, no_san 2000-2020, anemia 2000-2019
foreach v in undernut no_san anemia {
	gen `v'_d = `v' - L18.`v'
	gen `v'_n = `v'_d < 0 if (year==2019 & `v'_d<.)
}
sum *_d if year==2019
table (undernut_n) if year==2019
table (no_san_n) if year==2019
table (anemia_n) if year==2019

// values for Vietnam
l undernut if year==2018 & countrycode=="VNM"
l no_san if year==2017 & countrycode=="VNM"
l anemia if year==2019 & countrycode=="VNM"
l lead_BLL5 if year==2019 & countrycode=="VNM"

graph combine undernut sanitation anemia lead, rows(1) ysize(2) iscale(*1.7) ///
	note("LI, LM, UM, HI are World Bank Low Income, Lower Middle Income, Upper Middle Income, and High Income " "country categories. World Bank (2021) data on undernutrition in 2018, sanitation in 2017, child anemia (< age 5) in 2019, " "and Rees and Fuller (2020) data on child lead (< age 20) in 2019.", size(*2))
graph export ../../draft/images/riskfact.pdf, fontface("CMU Serif") replace
exit

collapse undernut no_san anemia, by(wb_cat year)
line undernut no_san anemia year if wb_cat==1 & year>2000
set more on
more
line undernut no_san anemia year if wb_cat==2 & year>2000
more
line undernut no_san anemia year if wb_cat==3 & year>2000
more
line undernut no_san anemia year if wb_cat==4 & year>2000

